#include "htmlWriter.h"

HTMLWriter::HTMLWriter(vector<Place>& places):
	places_(places) { }	

HTMLWriter::~HTMLWriter() { }

void HTMLWriter::Save(string path){
	string TITLE = "Title";	

    ofstream fout;
    fout.open(path.c_str());   

    fout << "<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">\n";
    fout << "<html>\n";
    fout << "<head>\n";
	fout << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"; 
    fout << "\t<title>" << TITLE.c_str() << "</title>\n";
    fout << "</head>\n";
    fout << "<body>\n";

    fout<<"\t<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n";

	fout << "\t\t<tr>\n";	
	fout << "\t\t\t<td>" << "Название" << "</td>\n";
	fout << "\t\t\t<td>" << "Адрес" << "</td>\n";	
	fout << "\t\t\t<td>" << "Рейтинг" << "</td>\n";	
	fout << "\t\t</tr>\n";	

	for(std::vector<Place>::iterator i = places_.begin(); i != places_.end(); ++i){
		fout << "\t\t<tr>\n";	
		fout << "\t\t\t<td>" << (*i).getName() << "</td>\n";
		fout << "\t\t\t<td>" << (*i).getAddress() << "</td>\n";	
		fout << "\t\t\t<td>" << (*i).getRank() << "</td>\n";	
		fout << "\t\t</tr>\n";	
	}

    fout << "\t</table>\n";

    fout << "</body>\n";
    fout << "</html>\n";

    fout.close();
}
